﻿using MediatR;
using Traceability.App.Api.Application.Command.Get;
using Traceability.App.Domain;
using Traceability.App.ErrorCode;
using Traceability.App.Instructure;

namespace Traceability.App.Api.Application.Handler.Get
{
    public class GetTuCompanyHandler : IRequestHandler<GetTuCompanyCommand, ApiResult<SlaughterCompany>>
    {
        private readonly IBaseRepository<SlaughterCompany> slaughterRepo;

        public GetTuCompanyHandler(IBaseRepository<SlaughterCompany> slaughterRepo) 
        {
            this.slaughterRepo = slaughterRepo;
        }
        public Task<ApiResult<SlaughterCompany>> Handle(GetTuCompanyCommand request, CancellationToken cancellationToken)
        {
            ApiResult<SlaughterCompany> res = new ApiResult<SlaughterCompany>();
            var slaughter = slaughterRepo.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            res.Code = ApiEnum.Success;
            res.Data = slaughter;
            res.Msg = "显示屠宰企业成功";
            return Task.FromResult(res);
        }
    }
}
